package rlyy.framework.core.resolver.argument;

import com.alibaba.fastjson.TypeReference;
import rlyy.framework.core.common.request.FullRequest;
import org.springframework.stereotype.Component;

import java.lang.reflect.Parameter;
import java.util.Map;

/**
 * @author yuanqinglong
 * @since 2020/7/20 11:38
 */
@Component
public class MapMethodArgumentResolver implements MyHandlerMethodArgumentResolver {


    @Override
    public boolean supportsParameter(Parameter parameter) {
        return parameter != null && parameter.getAnnotations().length == 0 && Map.class.isAssignableFrom(parameter.getType());
    }

    @Override
    public Object resolveArgument(Parameter parameter, FullRequest fullRequest) {
            return fullRequest.getData().toJavaObject(new TypeReference<Map<String, Object>>() {
            });
    }

    @Override
    public int getOrder() {
        return 60;
    }
}
